package com.yanfan.alarm.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.alarm.domain.NjDefenceAreaInfo;
import com.yanfan.alarm.service.INjDefenceAreaInfoService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 防区状态Controller
 *
 * @author genluo
 * @date 2024-10-31
 */
@Api(tags = "防区状态")
@RestController
@RequestMapping("/alarm/defenceArea")
public class NjDefenceAreaInfoController extends BaseController {
    @Autowired
    private INjDefenceAreaInfoService njDefenceAreaInfoService;

    /**
     * 查询防区状态列表
     */
    @ApiOperation("防区状态分页列表")
    @PreAuthorize("@ss.hasPermi('alarm:defenceArea:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjDefenceAreaInfo njDefenceAreaInfo) {
        startPage();
        List<NjDefenceAreaInfo> list = njDefenceAreaInfoService.queryPageList(njDefenceAreaInfo);
        return getDataTable(list);
    }

    /**
     * 导出防区状态列表
     */
    @ApiOperation("导出防区状态列表")
    @PreAuthorize("@ss.hasPermi('alarm:defenceArea:export')")
    @Log(title = "防区状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjDefenceAreaInfo njDefenceAreaInfo) {
        List<NjDefenceAreaInfo> list = njDefenceAreaInfoService.queryPageList(njDefenceAreaInfo);
        ExcelUtil<NjDefenceAreaInfo> util = new ExcelUtil<NjDefenceAreaInfo>(NjDefenceAreaInfo.class);
        util.exportExcel(response, list, "防区状态数据");
    }

    /**
     * 获取防区状态详细信息
     */
    @ApiOperation("获取防区状态详细信息")
    @PreAuthorize("@ss.hasPermi('alarm:defenceArea:query')")
    @GetMapping(value = "/{defenceAreaId}")
    public AjaxResult getInfo(@PathVariable("defenceAreaId") String defenceAreaId) {
        return success(njDefenceAreaInfoService.getById(defenceAreaId));
    }

    /**
     * 新增防区状态
     */
    @ApiOperation("新增防区状态")
    @PreAuthorize("@ss.hasPermi('alarm:defenceArea:add')")
    @Log(title = "防区状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody NjDefenceAreaInfo njDefenceAreaInfo) {
        return toAjax(njDefenceAreaInfoService.save(njDefenceAreaInfo));
    }

    /**
     * 修改防区状态
     */
    @ApiOperation("修改防区状态")
    @PreAuthorize("@ss.hasPermi('alarm:defenceArea:edit')")
    @Log(title = "防区状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody NjDefenceAreaInfo njDefenceAreaInfo) {
        return toAjax(njDefenceAreaInfoService.updateById(njDefenceAreaInfo));
    }

    /**
     * 删除防区状态
     */
    @ApiOperation("删除防区状态")
    @PreAuthorize("@ss.hasPermi('alarm:defenceArea:remove')")
    @Log(title = "防区状态", businessType = BusinessType.DELETE)
    @DeleteMapping("/{defenceAreaIds}")
    public AjaxResult remove(@PathVariable String[] defenceAreaIds) {
        return toAjax(njDefenceAreaInfoService.removeBatchByIds(Arrays.asList(defenceAreaIds)));
    }
}
